function delSelectedNode(obj,hObject,eventData)

% This file is part of CISNE.
%
%     CISNE is free software: you can redistribute it and/or modify
%     it under the terms of the GNU General Public License as published by
%     the Free Software Foundation, either version 3 of the License, or
%     any later version.
%
%     CISNE is distributed in the hope that it will be useful,
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%     GNU General Public License for more details.
%
%     You should have received a copy of the GNU General Public License
%     along with CISNE.  If not, see <http://www.gnu.org/licenses/>.

% Copyright 2011. Jose Maria Garcia-Valdecasas Bernal

%delete current grid (using context menu).

node=obj.m_tree.getSelectedNodes();
if ~isempty(node)%should always exist a node, just a security check.
    node=node(1);
    type=node.getValue();
    type=char(type(2));
    %determine kind of Data.
    
    parent=node.getParent();
    temp=parent.getParent();
    while(temp~=obj.m_tree.Root())
        parent=temp;
        temp=parent.getParent();
    end
    %if we are out of the loop, we know which one is the parent node.
    kind=parent.getValue();
    kind=char(kind(2));
    
    %remove grid from gridList
    obj.m_grids=rmfield(obj.m_grids,type);
    
    %remove from Display Widget if exists.
    handles=guidata(obj.m_figure);
    switch kind
        case 'INPUT'
            handles.DisplayWidget.delInputGrid(type);
        case 'COMPUTATIONAL'
            handles.DisplayWidget.delCompGrid(type);
        case 'CPOINTS'
            handles.DisplayWidget.delCPoint(type);
    end
    
    nP = node.getPreviousSibling;
    nN = node.getNextSibling;
    if ~isempty( nN )
        obj.m_tree.setSelectedNode( nN );
    elseif ~isempty( nP )
        obj.m_tree.setSelectedNode( nP );
    else
        obj.m_tree.setSelectedNode( node.getParent );
    end
    tModel=get(obj.m_tree,'Model');
    tModel.removeNodeFromParent( node );
    
    
    
%     
%     kind=node.getValue();
%     kind=char(kind(2));
%     
%     if strfind(kind,'point')
%         %its a control point
%         
%     elseif strfind(kind,'cNest')|strfind(kind,'cMain')
%         %its a computational mesh
%         
%     else
%         %if not, it's an input grid. 
%     
%     end
    
end

end

